import apiStore from "@/stores/apiStore"
import { App } from "vue"

export const initApi = (app: App<Element>) => {
  return new Promise((resolve) => {
    const apis = import.meta.glob([`../views/**/api.ts`, `../api/**/common.ts`])
    
    const apiPromises = Object.keys(apis)
      .map(x => apis[x]).map(f => f())
    
    Promise.all(apiPromises).then((list: any[]) => {
      const store = apiStore()
      for (let module of list) {
        for (let key in module) {
          const moduleApis = module[key]
          
          store.assginApi(moduleApis)
        }
      }
      app.mount('#app')
    })
  })
}